package com.csdj.springboottest.common;


import java.util.*;

public class ResourcesBoudleUtil {

    private static Map<Locale, ResourceBundle> bundles = new HashMap<>();

    /**
     * 根据语言查询错误代码对应的错误描述
     * @param code
     * @param lang
     * @return
     */
    public static String getMessage(String code,Locale lang){
        if(lang == null){
            lang = Locale.CHINA;
        }
        ResourceBundle bundle = bundles.get(lang);
        if(bundle == null){
            //加载properties消息文件
            bundle = ResourceBundle.getBundle("message", lang);
            if(bundle != null){
                bundles.put(lang,bundle);
            }
        }
        return bundle.getString(code);
    }
}
